/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

var React = require("react");
var {
  AppRegistry,
  StyleSheet,
  Text,
  View
} = require("react-native");
var Son = require("./son");


var imoccApp =  React.createClass({
  getDefaultProps:function(){
    console.log('getDefaultProps','父组件')
  },
  getInitialState: function () {
      console.log('getInitialState','父组件')
       return {
           times: 5,
           hit:false
       };
   },
  timePlus(){
    var times =this.state.times
    times+=3
    this.setState({
      times:times
    })
 },
  timeReset:function(){
    this.setState({
      times:0
    })
  },
  willHit:function(){
    this.setState({
      hit:!this.state.hit

    })
  },
componentWillMount(){
  console.log('ComponentWillMont','父组件即将被安装')
},
render() {
    console.log('render','父组件渲染')
  return (
    <View style={styles.container}>
      {
        this.state.hit ? <Son times={this.state.times} timeReset={this.timeReset}/> : null
      }

      <Text style={styles.welcome} onPress= {this.timeReset} >
       老子说：心情好就放你一马
      </Text>
      <Text onPress= {this.willHit} style={styles.instructions}>
         到底揍不揍
      </Text>
      <Text  style={styles.instructions}>
         就揍你{this.state.times}次而已
      </Text>
      <Text onPress= {this.timePlus} style={styles.instructions}>
         不听话，在揍三次
      </Text>
    </View>
  );
},
componentDidMount(){
    console.log('ComponentWillMont','父组件即将被安装完毕')
},
shouldComponentUpdate(){
  console.log('shouldComponentWillUpdate','父要不要更新')
  return true
},
componentWillUpdate(){
    console.log('ComponentWillMont','父组件即将被更新完毕')
},

componentDidUpdate(){
      console.log('componentDidUpdate','父组件即将被更新完毕')
  },
})
var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('imoccApp', () => imoccApp);
